package com.school.movie.common.config;

import com.school.movie.common.interceptor.PermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @author zhaoren
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${upload.absPath}")
    private String absPath;

    @Autowired
    private PermissionInterceptor permissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        InterceptorRegistration registration = registry.addInterceptor(permissionInterceptor);
        registration.addPathPatterns("/**");
        registration.excludePathPatterns(
                "/",
                "/**/login.jsp",
                "/**/login",
                "/mobile/**",
                "/**/enimg",
                "/**/*.html",
                "/**/*.js",
                "/**/*.css",
                "/**/*.xls",
                "/**/*.jpg",
                "/**/*.png",
                "/**/*.gif",
                "/page/**",
                "/**/frontcss/**",
                "/**/frontjs/**",
                "/**/fontimg/**"
//                "/**/front/**",
        );
    }

    /**
     * 首页,配置addViewControllers不生效的话用WebMvcConfigurationSupport来配置
     *
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("front/login.jsp");
        registry.addViewController("/login.jsp").setViewName("login.jsp");
        registry.addViewController("main").setViewName("tabs");
//        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }


    /**
     * 配置图片的映射地址
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/card/**").addResourceLocations("file:" + absPath);
    }
}
